package com.opennetexam.manager.itemmodel;

import com.openexam.openqti.openqtipaperquestion.OpenItemResult;
import com.openexam.openqti.openqtipaperquestion.OpenResultResponseVariable;
import com.openexam.openqti.openqtipaperquestion.OpenScoreOutcomeVariable;
import com.openexam.openqti.qti.BaseTypeType;
import com.openexam.openqti.qti.CardinalityType;
import com.openexam.openqti.qti.SessionStatusType;
import com.opennetexam.manager.common.CommonFunction;
import com.opennetexam.manager.dto.AnswerModelWithCorr;
import com.opennetexam.manager.dto.ItemTemplate;
import com.opennetexam.manager.utils.BCConvert;
import com.opennetexam.manager.utils.DateUtil;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.Date;
import java.util.List;

/**
 * @author 奶茶
 * Created by on 2017/12/14.
 * 填空题
 */
public class ItemTextEntryCreater extends IHtmlCreater{

    @Override
    public OpenItemResult save(ItemTemplate template) {
        //考生答案
        List<String> candidateResponses = template.getCandidateResponses();
        //正确答案
        List<String> correctResponses = template.getCorrectResponses();

        //保存作答
        OpenResultResponseVariable openResultResponseVariable = new OpenResultResponseVariable("RESPONSE", CardinalityType.SINGLE, BaseTypeType.IDENTIFIER, correctResponses, candidateResponses);

        //判分
        //double candScores = 0;
        //Double candScore = CommonFunction.getDoubleDiv(template.getScore(), Double.valueOf(String.valueOf(correctResponses.size())));
        //for (int i=0;i < correctResponses.size();i++){
        //    if(!BCConvert.ToDBC(correctResponses.get(i).toUpperCase()).equals(BCConvert.ToDBC(candidateResponses.get(i).toUpperCase()))){
        //
        //    }else{
        //        candScores += candScore;
        //    }
        //}
        //OpenScoreOutcomeVariable openScoreOutcomeVariable = new OpenScoreOutcomeVariable(template.getScore(), candScores);
        OpenScoreOutcomeVariable openScoreOutcomeVariable = new OpenScoreOutcomeVariable(template.getScore(), 0);

        return new OpenItemResult(template.getIdentifier(), DateUtil.dateToXmlDate(new Date()),template.getSequenceIndex(), SessionStatusType.INITIAL,0,template.getMarked(),CommonFunction.getStatus(template.getItemCompletionStatus()),openResultResponseVariable,openScoreOutcomeVariable);
    }

    @Override
    public String getPreview(Boolean isShowAnswer) {
        throw new NotImplementedException();
    }

    @Override
    public List<String> getItemResult(OpenItemResult openItemResult) {
        throw new NotImplementedException();
    }

    @Override
    public double judeScore(AnswerModelWithCorr answerModel) {
        throw new NotImplementedException();
    }
}
